﻿Public Class frmConsultaCargoFuncao

    Private cargo As New _cargoFuncao
    Private DTVCargoFuncao As DataView

    Private _idCagoFuncao As Integer
    Public Property idCagoFuncao() As Integer
        Get
            Return _idCagoFuncao
        End Get
        Set(ByVal value As Integer)
            _idCagoFuncao = value
        End Set
    End Property
    Private _dsCargoFuncao As String
    Public Property dsCargoFuncao() As String
        Get
            Return _dsCargoFuncao
        End Get
        Set(ByVal value As String)
            _dsCargoFuncao = value
        End Set
    End Property

    Private Sub preecheGriCargos()

        dgvCargoFuncoes.AutoGenerateColumns = False
        DTVCargoFuncao = cargo.consultaCargoFuncao.Tables("dataSet").DefaultView
        dgvCargoFuncoes.DataSource = DTVCargoFuncao

    End Sub

    Private Sub frmConsultaCargoFuncao_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        preecheGriCargos()

    End Sub

    Private Sub dgvCargoFuncoes_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCargoFuncoes.CellContentDoubleClick
        Me._idCagoFuncao = dgvCargoFuncoes.CurrentRow.Cells("O_ID_CARGOFUNCAO").Value
        Me._dsCargoFuncao = dgvCargoFuncoes.CurrentRow.Cells("O_DS_CARGOFUNCAO").Value
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub btnInserir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCadastraNovo.Click

        Dim j As New frmCadastroCargoFuncao("Inserir", 0, "")
        j.ShowDialog()
        preecheGriCargos()

    End Sub

    Private Sub btnAlterar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlterar.Click

        Dim j As New frmCadastroCargoFuncao("Alterar", dgvCargoFuncoes.CurrentRow.Cells("O_ID_CARGOFUNCAO").Value, dgvCargoFuncoes.CurrentRow.Cells("O_DS_CARGOFUNCAO").Value)
        j.ShowDialog()
        preecheGriCargos()

    End Sub

    Private Sub txtPesquisar_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPesquisar.TextChanged

        DTVCargoFuncao.RowFilter = "O_DS_CARGOFUNCAO LIKE '%" & txtPesquisar.Text & "%'"
        dgvCargoFuncoes.DataSource = DTVCargoFuncao


    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

        preecheGriCargos()

    End Sub

    Private Sub txtPesquisar_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPesquisar.KeyDown
        If e.KeyCode = Keys.Enter Then
            If dgvCargoFuncoes.RowCount = 1 Then
                Me._idCagoFuncao = dgvCargoFuncoes.Rows.Item(0).Cells("O_ID_CARGOFUNCAO").Value
                Me._dsCargoFuncao = dgvCargoFuncoes.Rows.Item(0).Cells("O_DS_CARGOFUNCAO").Value
                Me.DialogResult = Windows.Forms.DialogResult.OK
                Me.Close()
            End If
        End If
    End Sub
End Class